From 6afbf9110108b925fbbc9a318505f219ccb6e911 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Fri, 16 Oct 2009 04:06:30 +0000 Subject: [PATCH] bug 9982. Encapsulate wgCanonicalNamespaceNames. Patch by Scott Colcord, with updates --- CREDITS | 1 + includes/Namespace.php | 9 +++++++++ includes/Skin.php | 4 ++-- includes/SkinTemplate.php | 6 +++--- includes/Title.php | 12 ++++++------ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CREDITS b/CREDITS index c8598701f8..f242963433 100644 --- a/CREDITS +++ b/CREDITS @@ -104,6 +104,7 @@ following names for their contribution to the product. * Robert Treat * RockMFR * ST47 +* Scott Colcord * Simon Walker * Stefano Codari * Str4nd diff --git a/includes/Namespace.php b/includes/Namespace.php index f9c23111e6..a9601b4e8c 100644 --- a/includes/Namespace.php +++ b/includes/Namespace.php @@ -107,6 +107,15 @@ class MWNamespace { ? $index - 1 : $index; } + + /** + * Returns whether the specified namespace exists + */ + public static function exists( $index ) { + global $wgCanonicalNamespaceNames; + return isset( $wgCanonicalNamespaceNames[$index] ); + } + /** * Returns the canonical (English Wikipedia) name for a given index diff --git a/includes/Skin.php b/includes/Skin.php index 4a92159839..a0c3311ef1 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -357,7 +357,7 @@ class Skin extends Linker { } global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension; global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang; - global $wgCanonicalNamespaceNames, $wgOut, $wgArticle; + global $wgOut, $wgArticle; global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths; global $wgUseAjax, $wgAjaxWatch; global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI; @@ -365,7 +365,7 @@ class Skin extends Linker { global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest; $ns = $wgTitle->getNamespace(); - $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText(); + $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText(); $separatorTransTable = $wgContLang->separatorTransformTable(); $separatorTransTable = $separatorTransTable ? $separatorTransTable : array(); $compactSeparatorTransTable = array( diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 90cf2bab85..50024c2c57 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -134,7 +134,7 @@ class SkinTemplate extends Skin { global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments; - global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames; + global $wgArticlePath, $wgScriptPath, $wgServer; wfProfileIn( __METHOD__ ); @@ -226,8 +226,8 @@ class SkinTemplate extends Skin { $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) ); $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) ); - $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ? - $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] : + $nsname = MWNamespace::exists( $this->mTitle->getNamespace() ) ? + MWNamespace::getCanonicalName( $this->mTitle->getNamespace() ) : $this->mTitle->getNsText(); $tpl->set( 'nscanonical', $nsname ); diff --git a/includes/Title.php b/includes/Title.php index 134ad280e4..422a50b554 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -546,7 +546,7 @@ class Title { * @return \type{\string} Namespace text */ public function getNsText() { - global $wgContLang, $wgCanonicalNamespaceNames; + global $wgContLang; if ( '' != $this->mInterwiki ) { // This probably shouldn't even happen. ohh man, oh yuck. @@ -555,8 +555,8 @@ class Title { // // Use the canonical namespaces if possible to try to // resolve a foreign namespace. - if( isset( $wgCanonicalNamespaceNames[$this->mNamespace] ) ) { - return $wgCanonicalNamespaceNames[$this->mNamespace]; + if( MWNamespace::exists( $this->mNamespace ) ) { + return MWNamespace::getCanonicalName( $this->mNamespace ); } } return $wgContLang->getNsText( $this->mNamespace ); @@ -3616,13 +3616,13 @@ class Title { * @return \type{\string} XML 'id' name */ public function getNamespaceKey( $prepend = 'nstab-' ) { - global $wgContLang, $wgCanonicalNamespaceNames; + global $wgContLang; // Gets the subject namespace if this title $namespace = MWNamespace::getSubject( $this->getNamespace() ); // Checks if cononical namespace name exists for namespace - if ( isset( $wgCanonicalNamespaceNames[$namespace] ) ) { + if ( MWNamespace::exists( $this->getNamespace() ) ) { // Uses canonical namespace name - $namespaceKey = $wgCanonicalNamespaceNames[$namespace]; + $namespaceKey = MWNamespace::getCanonicalName( $namespace ); } else { // Uses text of namespace $namespaceKey = $this->getSubjectNsText(); -- 2.20.1